package cn.hloger.spider.demo.carDemo.carDemo;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

/**
 * 测试的
 *
 * @author huanglong
 * @Description TODO
 * @data 2022/9/12
 */
@Service
public class AESTest {

    private static String AES_KEY = "mx0jJM1pqTGYeKuZ47otPw==";

    private static AES aes = new AES(Mode.CBC,
            Padding.PKCS5Padding,
            Base64.decode(AES_KEY),
            new byte[16]);

    public static JSONObject getJson() {
        String s = "{\"order_no\":\"176A1E20230907233916000000000299\",\"out_time\":\"2023-09-08 17:29:39\",\"plate_color\":1,\"total_parking_number\":230,\"park_id\":\"202307250008\",\"lane_id\":\"606000686a1799180017604000000000\",\"type\":0,\"car_type\":1,\"upload_time\":\"2023-09-08 17:29:40\",\"in_time\":\"2023-09-07 23:39:16\",\"plate_no\":\"贵A66666\",\"is_correction\":0,\"remain_parking_number\":145,\"lane_name\":\"卫泊控制机控制器0215\",\"open_parking_number\":145}\n";
        JSONObject json = JSONObject.parseObject(s);
        return json;
    }

    public static String aesEncrypt(AES aes, JSONObject json) {
        // 加密并进行Base转码
        return aes.encryptBase64(json.toString(), "UTF-8");
    }

    public static String aesdecrypt(AES aes, String encryptStr) {
        // 解密为字符串
        return aes.decryptStr(encryptStr);
    }


    public static void main(String[] args) {
        JSONObject json = getJson();
        System.out.println(json.toString());
        //加密
        String encrypt = EncryptUtils.aesEncrypt(aes, json);
        System.out.println(encrypt);
    }
}
